package com.itheima.d03_net_chat;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;

public class Server {
    // 所有的客户信息  客户端ip地址
   public static    Map<String, Socket> onlineUsers = new HashMap<>();

    public static void main(String[] args) throws IOException {
        ExecutorService pool = new ThreadPoolExecutor(
                30,
                34,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()


        );
        ServerSocket ss = new ServerSocket(10086);
        System.out.println("客户端已启动，等待客户端链接");
        while (true) {
            Socket severSocket = ss.accept();
            System.out.println("一个客户端链接了"+ severSocket.getInetAddress().getHostAddress());
            pool.execute(new ChatRunnable(severSocket));
        }
    }
}
